package sbc.group1.lab1.common;

import java.awt.Color;
import java.io.Serializable;

public class Order implements Serializable, Identifieable, Comparable<Order> {
    
    private int id=NO_ID;
    private final int numCars;
    private final Color color;
    private final Engine.Type engine;
    
    public Order(int numCars, Color color, Engine.Type engine) {
        this.numCars=numCars;
        this.color=color;
        this.engine=engine;
    }
    
    public boolean setId(int id) {
        if (hasId()) {
            return false;
        }else {
            this.id=id;
            return true;
        }
    }
    
    public int getId() {
        return id;
    }
    public int getNumCars() {
        return numCars;
    }
    
    public Color getColor() {
        return color;
    }
    
    public Engine.Type getEngine() {
        return engine;
    }

    @Override
    public boolean hasId() {
        return id!=NO_ID;
    }

    @Override
    public int compareTo(Order o) {
        return this.id - o.id;
    }
    
    public int hashCode() {
    	return id;
    }
    
    @Override
    public boolean equals(Object obj) {
    	if (obj==null) return false;
    	if (obj instanceof Order) {
    		return compareTo((Order) obj)==0;
    	}else {
    		return false;
    	}
    }

}
